package com.homework.api_email.controller;

import com.homework.api_email.services.EmailService;
import com.homework.util.ResultMsg;
import com.homework.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/email")
public class EmailController {

    @Autowired
    protected EmailService emailService;

    @RequestMapping("/send")
    public ResultMsg send(@RequestParam("email") String email, @RequestParam("code") String code) {
        boolean res = emailService.send(email, code);

        if(res == true) {
            return ResultUtil.success();
        } else {
            return ResultUtil.error(1, "邮件发送失败");
        }
    }

}
